﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using ThresholdAssistant.DataContract.Result;
using ThresholdAssistant.WebAPI.Models;
using ThresholdAssistant.WebAPI.Service;

namespace ThresholdAssistant.WebAPI.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/user")]
    public class UserController : BaseController
    {
        /// <summary>
        /// 用户服务
        /// </summary>
        public MemberService UserService { get; set; }

        /// <summary>
        /// 微信授权登录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("wechat-login")]
        [AllowAnonymous]
        public async Task<ContractResult<WechatLoginData>> WechatLoginAsync(WechatLoginParam param)
        {
            return await UserService.WechatLoginAsync(param.JsCode);
        }

        /// <summary>
        /// 检测token是否可用
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet("check-token")]
        [AllowAnonymous]
        public async Task<ContractResult> CheckToken(string token)
        {
            return await UserService.CheckTokenAsync(token);
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("get-info")]
        [AllowAnonymous]
        public async Task<ContractResult<MemberData>> GetInfoAsync(GetInfoParam param)
        {
            return await UserService.GetInfoAsync(param);
        }

        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("modify-wechat-info")]
        [AllowAnonymous]
        public async Task<ContractResult> ModifyWeChatInfoAsync(ModifyWeChatInfoParam param)
        {
            return await UserService.ModifyWeChatInfoAsync(param);
        }

        /// <summary>
        /// 更新用户手机号码
        /// </summary>
        /// <returns></returns>
        [HttpPost("modify-phone")]
        [AllowAnonymous]
        public async Task<ContractResult> ModifyPhoneAsync(ModifyPhoneParam param)
        {
            return await UserService.ModifyPhoneAsync(param);
        }

    }
}